<script>
    var url = '{{ .CommonIn.GetUrlByKey "admin/role/DoSubmit" }}';
    function subData (data){
        var loadIndex = layer.load(2);
        $.ajax({
            type: "post",
            url: url,
            data:data,
            success: function (res) {
                layer.close(loadIndex);
                console.log(res)
                if(res.code==0){
                    layer.alert(res.msg,function(index){
                        parent.CloseChild(true)
                    })
                }else{
                    layer.alert(res.msg)
                }
            },
            error:function(){
                layer.close(loadIndex);
            },
            complete:function (){

            }
        });
    }
    layui.use(['form', ], function () {
        var form = layui.form
            , layer = layui.layer
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 2) {
                    return '标题至少得2个字符啊';
                }
            }
        });
        $("#cancelAdd").click(function(e){
            e.preventDefault();
            parent.CloseChild(false)
        })
        //监听提交
        form.on('submit(submitForm)', function (data) {
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })

            subData(data.field)
            return false;
        });


        //表单初始赋值



    });
</script>